package com.levy.contronller.lamdaTest;

import java.util.function.BiFunction;
import java.util.function.Function;

public class FunctionTest2 {


    public static void main(String[] args) {


        FunctionTest2 functionTest2 = new FunctionTest2();
        System.out.println(functionTest2.compute1(2, v -> v * 3, v -> v * v));
        System.out.println(functionTest2.compute2(2, v -> v * 3, v -> v * v));

        System.out.println(functionTest2.compute3(2, 3, (v1, v2) -> v1 + v2));
        System.out.println(functionTest2.compute4(2, 3, (v1, v2) -> v1 + v2, v -> v * v));
    }


    public int compute1(int a, Function<Integer, Integer> function1, Function<Integer, Integer> function2) {
        Integer apply = function1.compose(function2).apply(a);
        return apply;
    }

    public int compute2(int a, Function<Integer, Integer> function1, Function<Integer, Integer> function2) {
        Integer apply = function1.andThen(function2).apply(a);
        return apply;
    }

    public int compute3(int a, int b, BiFunction<Integer, Integer, Integer> function1) {
        Integer apply = function1.apply(a, b);
        return apply;
    }

    public int compute4(int a, int b, BiFunction<Integer, Integer, Integer> function1, Function<Integer, Integer> function2) {
        Integer apply = function1.andThen(function2).apply(a, b);
        return apply;
    }
}
